//
//  LogViewController.m
//  DWL_Vogue
//
//  Created by diaowenli on 15/11/6.
//  Copyright (c) 2015年 Forlosan. All rights reserved.
//

#import "LogViewController.h"
#import "VogueHeader.h"
#import "WidthAndHeight.h"
#import "UMSocial.h"
#import "PersonViewController.h"
#import "Singleton.h"

@interface LogViewController ()
@property(nonatomic, retain)UIView *backView;
@property(nonatomic, retain) UIButton *SinaButton;
@property(nonatomic, retain) UIButton *TencentButton;
@property(nonatomic, retain) UIButton *WeChatButton;


@end

@implementation LogViewController
- (void)dealloc {
    [_backView release];
    [_SinaButton release];
    [_TencentButton release];
    [_WeChatButton release];

    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //  设置背景图片
    self.backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.backView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:self.backView];
    [_backView release];
    [self.backView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"backView.png"]]];
    //  CellBackView
    UIView *cellBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
    cellBackView.backgroundColor = [UIColor colorWithRed:0.807 green:0.861 blue:0.861 alpha:0];
    [self.backView addSubview:cellBackView];
    cellBackView.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.1];
    [cellBackView release];
    //  backButton
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeSystem];
    backButton.frame = CGRectMake(10, 20, 30, 30);
    [backButton setImage:[UIImage imageNamed:@"return.png"] forState:UIControlStateNormal];
    [backButton setTintColor:[UIColor whiteColor]];
    [cellBackView addSubview:backButton];
    [backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.SinaButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.SinaButton.frame = CGRectMake(WIDTH / 2 - 75, HEIGHT / 2, 150, 40);
    [self.backView addSubview:self.SinaButton];
    [self.SinaButton.layer setMasksToBounds:YES];
    [self.SinaButton.layer setCornerRadius:10];
    [self.SinaButton.layer setBorderWidth:1];
    [self.SinaButton.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    [self.SinaButton setTitle:@"新浪微博" forState:UIControlStateNormal];
    self.SinaButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.SinaButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.SinaButton addTarget:self action:@selector(SinaButtonAction) forControlEvents:UIControlEventTouchUpInside];
     NSLog(@"1");
    
//    self.TencentButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    self.TencentButton.frame = CGRectMake(WIDTH / 2 - 75, HEIGHT / 2 + 60, 150, 40);
//    [self.backView addSubview:self.TencentButton];
//    [self.TencentButton.layer setMasksToBounds:YES];
//    [self.TencentButton.layer setCornerRadius:10];
//    [self.TencentButton.layer setBorderWidth:1];
//    [self.TencentButton.layer setBorderColor:[[UIColor whiteColor] CGColor]];
//    [self.TencentButton setTitle:@"腾讯QQ" forState:UIControlStateNormal];
//    self.TencentButton.titleLabel.font = [UIFont systemFontOfSize:15];
//    [self.TencentButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [self.SinaButton addTarget:self action:@selector(TencentButtonAction) forControlEvents:UIControlEventTouchUpInside];
//    
//    self.WeChatButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    self.WeChatButton.frame = CGRectMake(WIDTH / 2 - 75, HEIGHT / 2 + 120, 150, 40);
//    [self.backView addSubview:self.WeChatButton];
//    [self.WeChatButton.layer setMasksToBounds:YES];
//    [self.WeChatButton.layer setCornerRadius:10];
//    [self.WeChatButton.layer setBorderWidth:1];
//    [self.WeChatButton.layer setBorderColor:[[UIColor whiteColor] CGColor]];
//    [self.WeChatButton setTitle:@"微信" forState:UIControlStateNormal];
//    self.WeChatButton.titleLabel.font = [UIFont systemFontOfSize:15];
//    [self.WeChatButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [self.WeChatButton addTarget:self action:@selector(WeChatButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)backAction {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)SinaButtonAction {
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        //          获取微博用户名、uid、token等
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
            [self dismissViewControllerAnimated:YES completion:nil];
            [Singleton shareSingleton].urlStr = snsAccount.iconURL;
            [Singleton shareSingleton].titleStr = snsAccount.userName;
            
        }});
    
    //获取accestoken以及新浪用户信息，得到的数据在回调Block对象形参respone的data属性
    [[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToSina  completion:^(UMSocialResponseEntity *response){
        NSLog(@"SnsInformation is %@",response.data);
//        [Singleton shareSingleton].urlStr = response.data[@"profile_image_url"];
//        [Singleton shareSingleton].titleStr = response.data[@"screen_name"];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
